var parse_xlsx = require("./parse_xlsx");
var parse_lang = require("./parse_lang");
var file_util = require("./public/file_util");
var Path = require('path');
var moduleName = process.argv[2];
var data_path = process.argv[3];
var export_c_path = process.argv[4]
var export_s_path = process.argv[5]
let copy_c_path = process.argv[6];
let copy_s_path = process.argv[7];
let copy_init_path = process.argv[8];
let init_file_name = process.argv[9];
let deleteDir = process.argv[10];
var cur_path = process.cwd()


var test = function() {
	Editor.log(" test ")
}


var parseAll = function(moduleName, data_path, export_c_path, export_s_path, cur_path, copy_c_path, copy_s_path, copy_init_path, init_file_name, deleteDir) {
    console.log(" moduleName`11211 ", moduleName)
    console.log(" data_path ", data_path)
	console.log(" export_c_path ", export_c_path)
	console.log(" export_s_path ", export_s_path)
	console.log(" cur_path ", cur_path)
	console.log(" copy_c_path ", copy_c_path)
	console.log(" copy_s_path ", copy_s_path)
	console.log(" deleteDir ", deleteDir)
	console.log(" copy_init_path ", copy_init_path)
	console.log(" init_file_name ", init_file_name)

	var lang_c_path = Path.join(export_c_path, 'lang')

	var json_c_path = Path.join(export_c_path, 'json')

	var lang_s_path = Path.join(export_s_path, 'lang')

    var json_s_path = Path.join(export_s_path, 'json')

    console.log(" lang_c_path ", lang_c_path)
	console.log(" json_c_path ", json_c_path)
	console.log(" lang_s_path ", lang_s_path)
    console.log(" json_s_path ", json_s_path)
console.log(" export_c_path", export_c_path)
console.log(" export_s_path", export_s_path)


	//创建目录
	var langFile = moduleName + "_lang_0.txt"
	if (deleteDir && deleteDir === "true") {
		file_util.delDir(export_c_path);
		file_util.delDir(export_s_path);
	}
	file_util.mkdir(export_c_path);
	file_util.mkdir(export_s_path);
	file_util.mkdir(lang_c_path);
	file_util.mkdir(lang_s_path);
	file_util.mkdir(json_c_path);
    	file_util.mkdir(json_s_path);
	file_util.mkdir(export_s_path+"/class");
	file_util.mkdir(export_c_path+"/class");
	file_util.mkdir(export_s_path+"/class/proto");
	file_util.mkdir(export_s_path+"/class/protodata");

	// 客户端数据初始化
	parse_xlsx.init(cur_path)
	parse_xlsx.readDir_c(data_path, export_c_path);
	parse_lang(moduleName, export_c_path);
	parse_xlsx.readDir_s(data_path, export_s_path);
	parse_lang(moduleName, export_s_path);

	// parse_ts(moduleName, export_path);
	console.log('copy_c_path  ===', copy_c_path, " json_c_path ", json_c_path, 'langFile', langFile)
	//将json文件复制到项目中
	if (copy_c_path && copy_c_path !== "nopath") {
		file_util.createDir(copy_c_path)
		file_util.copyDir(json_c_path, copy_c_path)
		file_util.copy(Path.join(export_c_path, langFile), Path.join(copy_c_path, langFile))
	}

	console.log('copy_init_path  ===', copy_init_path, " init_file_name ", init_file_name)

	if (copy_init_path && copy_init_path !== "nopath") {
		file_util.createDir(copy_init_path)
		file_util.copy(Path.join(copy_c_path, init_file_name), Path.join(copy_init_path, init_file_name))
		file_util.deleteFile(Path.join(copy_c_path, init_file_name));
	}


	console.log('copy_s_path  ===', copy_s_path, " json_s_path ", json_s_path, 'langFile', langFile)

	if (copy_s_path && copy_s_path !== "nopath") {
                     	file_util.createDir(copy_s_path)
    	    	file_util.copyDir(json_s_path, copy_s_path)
    	    	file_util.copy(Path.join(export_s_path, langFile), Path.join(copy_s_path, langFile))
               }
}



if (moduleName && data_path && export_c_path && export_s_path) {
	parseAll(moduleName, data_path, export_c_path, export_s_path, cur_path, copy_c_path, copy_s_path, copy_init_path, init_file_name, deleteDir);
}

module.exports.test = test;

module.exports.parseAll = parseAll;
